package cn.com.css.taxInspection.attention.service.impl;

import cn.com.css.taxInspection.attention.entity.*;
import cn.com.css.taxInspection.attention.mapper.AttentionIncomeMapper;
import cn.com.css.taxInspection.attention.service.AttentionIncomeService;
import cn.com.css.taxInspection.system.service.impl.HttpSessionService;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Slf4j
public class AttentionIncomeServiceImpl extends ServiceImpl implements AttentionIncomeService {

    @Resource
    private AttentionIncomeMapper attentionIncomeMapper;

    @Resource
    private HttpSessionService httpSessionService;

    @Override
    @DS("oracle")
    public Map<String, Object> incomeList(IncomeCondition req) {
        if (req.getJjSwjgdm().equals("ALL")) {
            req.setJjSwjgdm(null);
        }
        Map<String, Object> resMap = new HashMap<>();
        //案件类型0-全部 1-稽查 2-自查
        String caseType = req.getCaseType();
        List<Income> incomes = null;
        long total = 0;
        if ("0".equals(caseType)) {
            incomes = attentionIncomeMapper.incomeAllList(req);
            total = attentionIncomeMapper.incomeAllListTotal(req);
        } else if ("1".equals(caseType)) {
            incomes = attentionIncomeMapper.incomeJcList(req);
            total = attentionIncomeMapper.incomeJcListTotal(req);
        } else if ("2".equals(caseType)) {
            incomes = attentionIncomeMapper.incomeZcList(req);
            total = attentionIncomeMapper.incomeZcListTotal(req);
        }
        resMap.put("incomes", incomes);
        resMap.put("incomesTotal", total);
        return resMap;
    }

    @Override
    @DS("oracle")
    public Map<String, Object> incomelistForExport(IncomeCondition req) {
        String currentSwjgDm = httpSessionService.getCurrentDeptNo();
        String swjgDmTmp = currentSwjgDm.substring(0, 9);
        req.setAjszjgDm(swjgDmTmp + "00");
        Map<String, Object> resMap = new HashMap<>();
        String caseType = req.getCaseType();//案件类型0-全部 1-稽查 2-自查
        List<Income> incomes = null;
        if ("0".equals(caseType)) {
            incomes = attentionIncomeMapper.incomeAllListForExport(req);
        } else if ("1".equals(caseType)) {
            incomes = attentionIncomeMapper.incomeJcListForExport(req);
        } else if ("2".equals(caseType)) {
            incomes = attentionIncomeMapper.incomeZcListForExport(req);
        }
        resMap.put("incomes", incomes);
        return resMap;
    }

    @Override
    public List<LogRecord> logRecord(String jcajuuid) {
        return attentionIncomeMapper.logRecord(jcajuuid);
    }
}
